﻿using System.Linq;
using ZilLion.Core.Log;
using ZilLion.Core.TaskManager.Client.Core;
using ZilLion.TaskManager.Entity.Entity;
using ZilLion.TaskManager.Repository;


namespace ZilLion.Core.TaskManager.Client.Command
{
    /// <summary>
    ///     卸载任务命令
    /// </summary>
    public class UninstallTaskCommand : BaseCommand
    {
        private readonly TaskConfigRespository _taskConfigRespository = new TaskConfigRespository();

        public override void Execute()
        {
          
            TaskConfig taskConfig = null;
            var response = _taskConfigRespository.GetTaskConfigById(CommandInfo.Taskid);
            if ((response != null) && (response.TaskConfigList != null))
                taskConfig = response.TaskConfigList.FirstOrDefault();
            if (taskConfig == null)
            {
                ZilLionLogManager.GetLogger().Warn("{CommandInfo.Taskid}找不到对应CONFIG");
            }
    
            else
            {
                TaskExcuteProvider.GetInstance().UninstallSchedule(taskConfig.TaskModule);
                TaskRuntimePool.GetInstance().Remove(taskConfig.TaskModule);
            }
           
          
        }
    }
}